//websocket测试

import { WebSocketConnect } from './socket.js'

/*"#SKT_METHOD#":{
       "PONG":"心跳检测",
		   "BIND_USER":"绑定用户",
		   "SEND_MSG":"发送消息"
}*/

//参数封装
const _parameter = {
  //URL建立
  url: '192.168.3.120:18083/ws',
  //默认open后发送数据
  isDefaultSendData: true,
  /*
    发送的数据，默认已经封装成响应式；如果后续有问题再调整
    数据格式有待确定
    */
  data: ['test-data'],
  //webSocket连接建立成功
  onOpen: function (event) {
    console.log('webSocket连接建立成功', event)
  },
  //webSocket客户端接收数据成功
  onSuccess: function (event) {
    console.log('服务端发送数据成功', event)
  },
  //WebSocket连接关闭
  onClose: function (event) {
    console.log('WebSocket连接关闭', event)
  },
  //WebSocket连接发生异常
  onError: function (event) {
    console.log('WebSocket连接发生异常', event)
  },
}

const socket = WebSocketConnect(_parameter)
//出发发送数据
socket.sendData(['test-message'])

//触发关闭
socket.close()

//触发重联接
socket.reConnect()
